`timescale 1ns/1ps
module v_dresizer_1ppc
#( 
    parameter COLUMN_DOWN                       = 1'b1  ,
    parameter LINE_DOWN                         = 1'b1  ,
    parameter VIDEO_WIDTH                       = 13'd1920,    
    parameter VIDEO_HEIGHT                      = 13'd1080,   
    parameter PIEXL_WIDTH                       = 24    ,
    parameter S_AXIS_BYTES                      = 3     ,
    parameter S_AXIS_WIDTH                      = 24    ,
    parameter M_AXIS_BYTES                      = 3     ,
    parameter M_AXIS_WIDTH                      = 24    
)
(
input   aclk,
input   aresetn,
//input interface
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)input       [S_AXIS_WIDTH -1:0]  s_axis_tdata,
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)input                            s_axis_tvalid,
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)output                           s_axis_tready,
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)input       [0:0]                s_axis_tuser,
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)input       [0:0]                s_axis_tlast,
//output interface   
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)output      [M_AXIS_WIDTH-1:0]   m_axis_tdata,
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)output reg                      m_axis_tvalid,
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)input                            m_axis_tready,
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)output       [0:0]                m_axis_tuser,
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)output reg  [0:0]                m_axis_tlast

);


//
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)reg [15:0] line_cnt;
(* DONT_TOUCH = "yes", s="true",keep="true" *)(* mark_debug="true" *)reg [15:0] col_cnt;


always@(posedge aclk)
begin
    if(!aresetn)
    begin
        col_cnt <= 16'b0;
    end
    else
    begin
        if((s_axis_tvalid ==1'b1) && (s_axis_tlast==1'b1) && (s_axis_tready ==1'b1)) 
        begin
            col_cnt <= 16'b0;
        end
        else if((s_axis_tvalid ==1'b1) && (s_axis_tready==1'b1))
        begin
            col_cnt <= col_cnt + 1'b1;
        end
    end
end

always@(posedge aclk)
begin
    if(!aresetn)
    begin
        line_cnt <= 16'b0;
    end
    else
    begin
        if((s_axis_tvalid ==1'b1) && (s_axis_tlast==1'b1) && (s_axis_tready ==1'b1))
        begin
            line_cnt <= line_cnt+1;
        end
        else if((s_axis_tvalid ==1'b1) && (s_axis_tready==1'b1) && (s_axis_tuser[0]==1'b1))
        begin
            line_cnt <= 16'b0;    
        end
    end
end


//defalut odd 
generate
    if ((COLUMN_DOWN == 1'b1) && (LINE_DOWN == 1'b1))
    begin
        always @(*)
        begin
            if(!col_cnt[0] && !line_cnt[0])
            begin
                m_axis_tvalid = s_axis_tvalid;
            end
            else
            begin
                m_axis_tvalid = 1'b0;
            end
        end
        always @(*)
        begin
            if(!line_cnt[0] && col_cnt == (VIDEO_WIDTH-2))
            begin
                m_axis_tlast = 1'b1;
            end
            else
            begin
                m_axis_tlast = 1'b0;
            end
        end
    end
    else if ((COLUMN_DOWN == 1'b1) && (LINE_DOWN == 1'b0))
    begin
        always @(*)
        begin
            if(!col_cnt[0])
            begin
                m_axis_tvalid = s_axis_tvalid;
            end
            else
            begin
                m_axis_tvalid = 1'b0;
            end
        end

        always @(*)
        begin
            if(col_cnt == (VIDEO_WIDTH-2))
            begin
                m_axis_tlast = 1'b1;
            end
            else
            begin
                m_axis_tlast = 1'b0;
            end
        end
    end
    else if ((COLUMN_DOWN == 1'b0) && (LINE_DOWN == 1'b1))
    begin
        always @(*)
        begin
            if(!line_cnt[0])
            begin
                m_axis_tvalid = s_axis_tvalid;
                m_axis_tlast = s_axis_tlast;
            end
            else
            begin
                m_axis_tvalid = 1'b0;
                m_axis_tlast = 1'b0;
            end
        end
    end
    else           
    begin
        always @(*)
        begin
            begin
                m_axis_tvalid = s_axis_tvalid;
                m_axis_tlast = s_axis_tlast;
            end
        end
    end

endgenerate

//
assign s_axis_tready =  m_axis_tready;
assign m_axis_tdata  =  s_axis_tdata ;
assign m_axis_tuser  =  s_axis_tuser ;
////////////////

endmodule
